package com.demo.modules.mq.rabbit.service;

import com.demo.modules.mq.rabbit.RabbitAnnouncementMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 消息消费者
 *
 * @author Rog
 */
@Component
@Slf4j
public class RabbitMessageConsumerService {

    @RabbitListener(queues = "simple.queue01")
    public void listenSimpleQueueMessage(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("接收到的消息为:{}", rabbitAnnouncementMessage);
    }

    /**
     * work模式下的接收
     *
     * @param rabbitAnnouncementMessage
     * @throws InterruptedException
     */
    @RabbitListener(queues = "work.queue02")
    public void workQueueMq1(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("消费者1" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }

    /**
     * work模式下的接收
     *
     * @param rabbitAnnouncementMessage
     * @throws InterruptedException
     */
    @RabbitListener(queues = "work.queue02")
    public void workQueueMq2(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("消费者2" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }
}
